import {
	http
} from '@/api/service.js'

const state = {
	//客户端类型 app-tch app-p mp-tch mp-p
	appType: 'app-tch',
	
	appTheme: {
		checkColor: '#DA473A',
		appPageBgColor: '#FAFAFA'
	}
}

const mutations = {
	switchAppType(state, appType) {
		const appDebug = uni.getStorageSync('appDebug');
		console.log(`appDebug:${appDebug}`)
		//http://pc.dev.dotflat.cn/api/
		//http://api.mq.dotflat.cn/api/
		//http://192.168.3.10:8001/api/
		
		//https://pc.dev.dotflat.cn/api/
		//http://mp.dev.dotflat.cn/
		//http://192.168.2.238:8019/api/
		console.log('switchAppType' + appType);
		state.appType = appType;
		
		if(process.env.NODE_ENV === 'development'){
			if (state.appType === 'app-tch' || state.appType === 'mp-tch') {
				if (appDebug) {
					http.config.baseURL = 'https://pc.jz1x.com/api/'
				} else {
					http.config.baseURL = 'https://pc.jz1x.com/api/'
				}
			} else {
				if (appDebug) {
					http.config.baseURL = 'https://wp.jz1x.com/'
				} else {
					http.config.baseURL = 'https://wp.jz1x.com/'
				}
			}
		}

		// #ifndef H5
			if (state.appType === 'app-tch' || state.appType === 'mp-tch') {
				if (appDebug) {
					http.config.baseURL = 'https://pc.jz1x.com/api/'
				} else {
					http.config.baseURL = 'https://pc.jz1x.com/api/'
				}
			} else {
				if (appDebug) {
					http.config.baseURL = 'https://wp.jz1x.com/'
				} else {
					http.config.baseURL = 'https://wp.jz1x.com/'
				}
			}
		// #endif
		uni.setStorage({
			key: 'appType',
			data: state.appType
		})
	},
}

export default {
  namespaced: true,
  state,
  mutations
}
